//
//  ApplyViewController.m
//  JiFengDaRen
//
//  Created by shouhan on 2018/3/23.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "ApplyViewController.h"
#import "YLProgressBar.h"

@interface ApplyViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView * webView;
@property (strong, nonatomic) YLProgressBar *newsProgressView;
@end

@implementation ApplyViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"贷款申请";
    
    self.webView = [UIWebView new];
    
    self.webView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight - KNAVIGATIONBARHEIGHT);
    
    [self.view addSubview:self.webView];
    
    self.webView.scalesPageToFit = YES;
    self.webView.delegate = self;
    
    NSURL *url = [NSURL URLWithString:applyUrl];//创建URL
    NSURLRequest* request = [NSURLRequest requestWithURL:url];//创建
    [self.webView loadRequest:request];//加载
    
//    CGFloat navHeight = [self vhl_navgationBarHeight];
    
    _newsProgressView = [[YLProgressBar alloc]initWithFrame:CGRectMake(0,KNAVIGATIONBARHEIGHT-KSTATUBARHEIGHT-2, KScreenWidth, 2)];
    NSArray *tintColors = @[[UIColor colorWithHexString:@"fdeded"],[UIColor colorWithHexString:@"#f85154"]];
    _newsProgressView.progressTintColors = tintColors;
    _newsProgressView.type   = YLProgressBarTypeFlat;
    _newsProgressView.hideStripes        = YES;
    _newsProgressView.hideTrack          = YES;
    _newsProgressView.behavior           = YLProgressBarBehaviorDefault;
    [self.navigationController.navigationBar addSubview: _newsProgressView];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_newsProgressView setProgress:1 animated:YES];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1  * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        
        _newsProgressView.backgroundColor = [UIColor clearColor];
        [_newsProgressView removeFromSuperview];
        
    });
    
    NSLog(@"成功");
    
}
//加载失败
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"%@",error.localizedDescription);
    [_newsProgressView setProgress:1 animated:YES];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1  * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        
        _newsProgressView.backgroundColor = [UIColor clearColor];
        [_newsProgressView removeFromSuperview];
        
    });
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
